package com.xiangxiangjd.analyse.serviceImpl;

    import com.xiangxiangjd.analyse.controller.helper.$;
    import com.xiangxiangjd.analyse.bean.Repair;
    import com.xiangxiangjd.analyse.mapper.RepairMapper;
    import com.xiangxiangjd.analyse.service.RepairService;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.xiangxiangjd.analyse.bean.result.ResultPage;
    import com.xiangxiangjd.analyse.controller.model.ApiResultModel;

    import org.springframework.stereotype.Service;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    /**
    * <p>
    *  服务实现类
    * </p>
    *
    * @author 肖守凯
    * @since 2021-03-18
    */
    @Service
    public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> implements RepairService {
    /** 添加Repair
    * @param repair  前端传进的参数
    * @return 返回统一信息
    */
    @Override
    public ApiResultModel addRepair(Repair repair  ) {
    if(this.save(repair )){
    return $.success();
    }else{
    return $.error("添加失败");
    }
    }
    /** 编辑跳转页面的回显数据Repair
    * @param id  前端传进的参数
    * @return 返回实体类
    */
    @Override
    public Repair selectRepairByIdRepair(String id ){
    return this.getById(id);
    }


    /** 编辑Repair
    * @param repair  前端传进的参数
    * @return 返回统一信息
    */
    @Override
    public ApiResultModel editRepair(Repair repair  ) {
    if(this.updateById(repair )){
    return $.success();
    }else{
    return $.error("编辑失败");
    }
    }
    /** 删除一条Repair
    * @param ids  前端传进的ID
    * @return 返回统一信息
    */
    @Override
    public   ApiResultModel delRepairs(  List ids ){

    int i = baseMapper.deleteBatchIds(ids);

    return $.success(i);

    }

    /** 分页查询Repair
    * @param page  页码
    * @param limit  查几条
    * @param repair  前端传进的参数
    * @return 返回统一分页信息
    */
    @Override
    public  ResultPage findRepairByPage(Integer page, Integer limit,Repair repair){
    Map
    <String, Object> paramMap = new HashMap<>();
    paramMap.put("page", (page - 1) * limit);
    paramMap.put("limit", limit);
    paramMap.put("repair", repair);
    List<Repair> list = baseMapper.selectMyPage(paramMap);
    Integer count = baseMapper.countMyPage(paramMap);
    ResultPage<Repair> resultPage = new ResultPage<>();
    resultPage.setCode(0);
    resultPage.setCount(count);
    resultPage.setMsg("成功");
    resultPage.setData(list);
    return resultPage;
    }
    }
